
<template>
    <div>
      
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="clickAdd">新增</el-button>
          </el-col>
        </el-row>

    <el-table v-loading="loading" :data="industryList">
          <!-- <el-table-column type="selection" width="50" align="center" /> -->
          <el-table-column label="id" align="center" key="id" prop="id" />
          <el-table-column label="课程类型名称" align="center" key="name" prop="name"/>
          <el-table-column label="状态" align="center" min-width="120">
        <template slot-scope="scope">
          <span key="status" prop="status" v-if="scope.row.status == 0">正常</span>
          <span key="status" prop="status" v-if="scope.row.status == 1">禁用</span>
        </template>
          </el-table-column>
         <el-table-column label="修改状态" align="center" key="status">
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row.status"
                active-value="0"
                inactive-value="1"
                @change="statusChange(scope.row)"
              ></el-switch>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="250"
            class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                >修改</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>

          <!-- 分页 -->
        <pagination
          v-show="this.sum > 0"
          :total="this.sum"
          :page.sync="queryParams.page"
          :limit.sync="queryParams.number"
          @pagination="selectIndustry"
        />

    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="类型名称" prop="name">
              <el-input
                v-model="form.name"
                placeholder="请输入类型名称"
                maxlength="40"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    </div>
</template>
  
  <script>
  import {
  selectIndustryApi,
  insertIndustryApi,
  updataIndustryApi,
  deleteIndustryApi,
  deleteIndustryStatusApi
} from "@/api/system/shuxing/type";

  export default {
      name: "shuxing",
      data() {
    return {
      // 遮罩层
      loading: true,
      loadingBatch: true,
      refreshTable: true,
      // 导出遮罩层
      exportLoading: false,
      // 学院表格数据
      industryList: null,
      courseList: null,
      sum: 0,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态数据
      ids: [],
      semCode: null,
      
      form: {},
      //   collegeId: undefined,
      // 查询参数
      queryParams: {
        page: 1,
        number: 10,
        name: undefined,
      },
      // // 列信息
      columns: [
        { key: 0, label: `类型编号`, visible: true },
        { key: 1, label: `类型名称`, visible: true },
        { key: 2, label: `状态`, visible: true },
      ],
      // 表单校验
      rules: {},
      dialogTableVisible: false
    };
    },
    watch: {},
        created() {
        this.selectIndustry();
    },
    methods: {
        //查询行业
        selectIndustry() {
        selectIndustryApi(this.queryParams)
        .then((data) => {
          this.industryList = data.data.returnDate;
          this.sum = data.data.paginationData.sum;
          this.loading = false;
            })
        .catch(() => {
          this.industryList = null;
          this.sum = 0;
          this.loading = false;
            });
        },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        name: undefined,
        status:undefined
      };
       if (this.$refs["form"]) {
		    this.$refs["form"].resetFields();
	    }
    },
       // 角色状态修改
    statusChange(row) {
      let text = row.status === "0" ? "启用" : "停用";
      this.$confirm('确认要"' + text + '""' + row.name + '"课程吗?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(()=> {
          deleteIndustryStatusApi({
            "id": row.id,
            "status": row.status
          }).then(()=>{
            this.$message({
               type: 'success',
              message: '修改成功'
            });
          })
        }).catch(()=> {
          row.status = row.status === "0" ? "1" : "0";
        });
    },

    /** 重置按钮操作 */
    resetQuery() {
      if (this.$refs["queryForm"]) {
        this.$refs["queryForm"].resetFields();
      }
      this.selectIndustry();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$confirm('是否确认删除批次id为"' + row.id + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        deleteIndustryApi({
          id: row.id,
        }).then((data) => {
          this.selectIndustry();
          this.$message({
            type: "success",
            message: "删除成功",
          });
        });
      });
    },
    
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.title = "修改类型";
      this.reset();
      selectIndustryApi({
        id: row.id,
        page: 1,
        number: 1,
      }).then(() => {
        this.form.id = row.id;
        this.form.name = row.name;
        this.open = true;
        this.selectIndustry();
      });
    },
      clickAdd() {
      this.title = "新增类型";
      this.open = true;
      this.reset();
    },
     /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != undefined) {
            updataIndustryApi(this.form).then((data) => {
              this.open = false;
              this.selectIndustry();
              this.reset();
              if(data.code==200){
                this.$message({
                  type: "success",
                  message: "修改成功"
              });
              }
            });
          } else {
            insertIndustryApi(this.form).then((data) => {
              this.open = false;
              this.selectIndustry();
              this.reset();
              if(data.code==200){
                this.$message({
                  type: "success",
                  message: "新增成功"
              });
              }
            });
          }
        }
      });
    }, // 取消按钮
    cancel() {
      this.open = false;
    },


    },
       
  
  }
  </script>
  
  <style>
  
  </style>